package com.retoc.graduationtravel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.retoc.graduationtravel.domain.City;
import com.retoc.graduationtravel.service.CityService;
import com.retoc.graduationtravel.mapper.CityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author retoc
 * @description 针对表【city】的数据库操作Service实现
 * @createDate 2022-04-17 09:44:34
 */
@Service
public class CityServiceImpl extends ServiceImpl<CityMapper, City>
        implements CityService {

    @Autowired
    CityMapper cityMapper;

    @Override
    public Map<String, List<City>> getacronym() {
        Map<String, List<City>> map = new HashMap<>();
        List<String> spellFirst = cityMapper.getSpellFirst();
        for (int i = 0; i < spellFirst.size(); i++) {
            QueryWrapper<City> qw = new QueryWrapper<>();
            String letter = spellFirst.get(i).toLowerCase();
            qw.likeRight("spell", letter);
            List<City> cities = cityMapper.selectList(qw);
            map.put(spellFirst.get(i), cities);
        }
        return map;
    }
}




